package com.samsungmobile.common.util;

import java.util.Map;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;

import com.ibatis.sqlmap.client.*;
import com.ibatis.common.resources.*;

import java.io.Reader;
import java.util.List;

import com.samsungmobile.common.util.SessionUtils;

public class WLConnection {
	private static Map confSession = null;

/*
	public WLConnection() {
		try {
			if(confSession == null) {
				confSession = SessionUtils.loadConf();
			}
		}catch(Exception e) {
			System.out.println("confSession Exception:"+e.getMessage());
		}
	}
*/
	public static Connection getConnection() {

		Context ctx = null;
		DataSource ds = null;
		Connection con = null;
		try{
		    ctx = new InitialContext();
		    ds = (javax.sql.DataSource)ctx.lookup("jdbc/oraclePool");
		    con = ds.getConnection();
		}catch(Exception e){
		}
		return con;
/*
		Connection con = null;
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		try {
			con = DriverManager.getConnection("jdbc:oracle:thin:@192.168.36.118:1531:BLOG", "gsms", "thrma34");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return con;
*/
	}

	/**
	 * Database Connection close
	 * 
	 * @param conn
	 */
	public static void releaseConnection(Connection conn) {
		try {
			if (conn != null) {
				conn.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Database Connection commit
	 * 
	 * @param conn
	 */
	public static void commitConnection(Connection conn) {
		try {
			if (conn != null) {
				conn.commit();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Database Connection rollback
	 * 
	 * @param conn
	 */
	public static void rollbackConnection(Connection conn) {
		try {
			if (conn != null) {
				conn.rollback();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
